<?php
/**
Tim phan extension cua 1 file.
VD : sonhaanh.net -> net, 
sonha.doc -> doc

$str = 'sonhaanh.net';
$soha = '';
for($i = 0; $i < strlen($str); $i++) {
if($str[$i] == '.') {
$soha = substr($str,$i + 1);
}
}
echo $soha.'<br>';
$remain = strpos($str,'.',0);
$sub = substr($str,$remain + 1);
echo $str.'<br>';
echo $remain.'<br>';
echo $sub.'<br>';
 **/

/**
C2: Tim phan extension cua 1 file.
$sub = '';
for ($i = 0; $i < strlen($str); $i++) {
    if ($str[$i] == '.') {
        $sub = substr($str, $i + 1);
    }
}
echo $sub;
 **/

/**
Test inplode function
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(":", $array);

echo $comma_separated; // lastname,email,phone
 **/

/**
Test memcached
$memcache = new Memcache;
$memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1′
echo "Server\"s version: " . $memcache->getVersion() . "<br /><hr />";
if (!$memcache->get("key"))
{
    $tmp_object = new stdClass;
$tmp_object->author = "Nguyen Hoang Duy";
$tmp_object->email = "nhduy88@gmail.com";
$tmp_object->website = "https://nhduy88.wordpress.com/";
$tmp_object->date = date("d-m-Y h:i:s", time());
$memcache->set("key",$tmp_object,false,30);
echo "<b>Store data in the cache (data will expire in 30 seconds)</b><br />";
}
else
{
echo "<b>Read data from cache you have created</b> <br />";
}
echo "<hr />Data from the cache:<br />";
echo "<pre>";
var_dump($memcache->get("key"));
echo "</pre>";
echo "<hr />Current date time:" .date("d-m-Y h:i:s", time());
 **/

/**
 Test echo va print
$a = 2;
echo "Day la $a"; // Đây là 2
echo 'Day la ',$a;
**/
/**
 * Test break
 */
//$arr = array('one', 'two', 'three', 'four', 'stop', 'five');
//while (list(, $val) = each($arr)) {
//    if ($val == 'stop') {
//        break;    /* You could also write 'break 1;' here. */
//    }
//    echo "$val<br />\n";
//}
/** Test List
$info = array('coffee', 'brown', 'caffeine');
// Listing all the variables
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";
**/
?>